package com.ruoyi.api.controller.order;

import com.ruoyi.api.controller.common.AbstractApiController;
import com.ruoyi.business.domain.dto.admin.product.OrderDTO;
import com.ruoyi.business.domain.dto.api.user.CreateOrderDTO;
import com.ruoyi.business.domain.product.TbOrder;
import com.ruoyi.business.domain.vo.order.OrderVo;
import com.ruoyi.business.service.product.TbOrderService;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.ruoyi.common.helper.LoginHelper.getUserId;


@Validated
@Api(value = "小程序用户兑换下单接口", tags = {"小程序用户兑换下单接口"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/miniapp/order")
public class ApiUserOrderController extends AbstractApiController {

    private final TbOrderService tbOrderService;
    @ApiOperation("用户积分商城下单校验")
    //@RepeatSubmit(interval = 500, timeUnit = TimeUnit.MILLISECONDS, message = "不允许重复提交")
    @PostMapping("/pointsMallVer")
    public R<Boolean> pointsMallver(@Validated @RequestBody CreateOrderDTO dto) {
        return tbOrderService.pointsMallVer(getUserId(), dto);
    }
    @ApiOperation("商品兑换生成订单")
    //@RepeatSubmit(interval = 500, timeUnit = TimeUnit.MILLISECONDS, message = "不允许重复提交")
    @PostMapping("/pointsMallCreate")
    public R<TbOrder> add(@Validated @RequestBody CreateOrderDTO dto) {
        //todo
//        return tbOrderService.create(getUserId(), dto);
        return tbOrderService.pointsMallCreate(getUserId(), dto);
    }
    //查看积分商城订单
    @ApiOperation("查看积分商城订单")
    @PostMapping("/pointsMallOrder")
    public TableDataInfo<OrderVo> pointsMallOrder(@Validated @RequestBody OrderDTO dto) {
        //todo
        dto.setUserId(getUserId());
//        dto.setUserId(1976192656376074241L);
     return tbOrderService.pointsMallOrder(dto);
    }
}
